<?php namespace Admin\Controller;
/*
 * 标签控制器
 * */
 	class TagController extends CommonController
 	{
 		protected $Tag;
 		public function __init()
 		{
 			$this->Tag = new \Common\Model\Tag;
 		}
 		/*
		 * 标签首页
		 * */
		 public function index()
		 {
		 	$Tagdata = $this->Tag->liebiao();
			View::with("Tagdata",$Tagdata);
		 	//载入页面
		 	View::make("tag");
		 }
		/*
		 * 添加标签方法
		 * */
		 public function addTag()
		 {
		 	
		 	if(IS_AJAX)
			{
				//p(!$this->Tag->add_Tag());die;
				if(!$this->Tag->add_Tag()){
					View::ajax(array("status"=>0,"message"=>$this->Tag->getError()));
				}else{
					View::ajax(array("status"=>1,'message'=>"添加成功"));
				}
			}
		 	//载入页面
		 	View::make();
		 }
		 /*
		  * 编辑标签
		  * */
		 public function resetTag()
		 {
		 	$tid = Q('get.tid',0,'intval');
		 	$olddata = $this->Tag->where("tid",$tid)->first();
			View::with('olddata',$olddata);
			if(IS_AJAX){
				if(!$this->Tag->reset_Tag())
				{
					View::ajax(array("status"=>0,"message"=>$this->Tag->getError()));
				}else{
					View::ajax(array("status"=>1,"message"=>"添加成功"));
				}
			}
		 	View::make();
		 }
		/*
		 * 删除标签
		 * */
		 public function del()
		 {
		 	$tid = Q("get.tid",0,"intval");
		 	if(!$this->Tag->del_Tag($tid)){
		 		$this->error($this->Tag->getError());
		 	}else{
		 		$this->success("删除成功！","Tag/index");
		 	}
		 }
 	}
	